package com.ruoyi.web.controller.librarian;

import java.util.List;

import com.ruoyi.system.service.ILibBookService;
import com.ruoyi.system.service.impl.LibBookServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.LibBook;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图书馆Controller
 *
 * @author ruoyi
 * @date 2024-05-09
 */
@Api("图书馆")
@Controller
@RequestMapping("/librarian/book")
public class LibBookController extends BaseController {
    private String prefix = "librarian/book";

    @Autowired
    private ILibBookService libBookService;

    @ApiOperation("图书列表")
    @RequiresPermissions("librarian:book:view")
    @GetMapping()
    public String book() {
        return prefix + "/book";
    }

    /**
     * 查询图书馆列表
     */
    @ApiOperation("搜索")
    @RequiresPermissions("librarian:book:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LibBook libBook) {
        startPage();
        List<LibBook> list = libBookService.selectLibBookList(libBook);
        return getDataTable(list);
    }

    /**
     * 导出图书馆列表
     */
//    @ApiOperation("导出图书")
    @RequiresPermissions("librarian:book:export")
    @Log(title = "图书馆", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LibBook libBook) {
        List<LibBook> list = libBookService.selectLibBookList(libBook);
        ExcelUtil<LibBook> util = new ExcelUtil<>(LibBook.class);
        return util.exportExcel(list, "图书馆数据");
    }

    /**
     * 新增图书馆
     */
    @ApiOperation("新增图书")
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存图书馆
     */
    @ApiOperation("新增图书")
    @RequiresPermissions("librarian:book:add")
    @Log(title = "图书馆", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LibBook libBook) {
        return toAjax(libBookService.insertLibBook(libBook));
    }

    /**
     * 修改图书馆
     */
    @ApiOperation("查看单个图书详情")
    @RequiresPermissions("librarian:book:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        LibBook libBook = libBookService.selectLibBookById(id);
        mmap.put("libBook", libBook);
        return prefix + "/edit";
    }

    /**
     * 修改保存图书馆
     */
    @ApiOperation("编辑图书")
    @RequiresPermissions("librarian:book:edit")
    @Log(title = "图书馆", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LibBook libBook) {
        return toAjax(libBookService.updateLibBook(libBook));
    }

    /**
     * 删除图书馆
     */
    @ApiOperation("删除图书")
    @RequiresPermissions("librarian:book:remove")
    @Log(title = "图书馆", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(libBookService.deleteLibBookByIds(ids));
    }
}
